package com.sgg.datastructure.stack;

/**
 * 链表实现
 * 0.存储数据
 * 1.构造器
 * 2.满
 * 3.空
 * 4.push
 * 5.pop
 * 6.遍历
 */
public class LinkStackOne {
    private StackNodeOne top;

    public boolean isEmpty() {
        return top == null;
    }

    public void push(int i) {
        StackNodeOne node = new StackNodeOne(i);
        node.next = top;
        top = node;
    }

    public int pop() {
        if (isEmpty()) {
            throw new RuntimeException("空");
        }
        int no = top.no;
        top = top.next;
        return no;
    }

    public void show() {
        StackNodeOne temp = top;
        while (temp != null) {
            System.out.println("loop" + temp.no);
            temp = temp.next;
        }
    }

    public static void main(String[] args) {
        LinkStackOne linkStack = new LinkStackOne();
        linkStack.push(1);
        linkStack.push(2);
        linkStack.push(3);
        linkStack.push(4);
        linkStack.show();
        System.out.println(linkStack.pop());
        System.out.println(linkStack.pop());
        System.out.println(linkStack.pop());
        linkStack.push(5);
        linkStack.push(6);
        linkStack.push(7);
        linkStack.show();
    }
}
